package top.lishuoboy.cloud.gateway.gateway9527.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GateWayConfig {
    /**
     * 70、Gateway配置路由的两种方式
     * 方式一：在配置文件yml中配置，见上一章节
     * 方式二：代码中注入RouteLocator的Bean
     * http://localhost:9527/guonei
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();

        routes.route("path_route_guonei", route -> route.path("/guonei").uri("http://news.baidu.com/guonei")).build();

        return routes.build();
    }
}